import 'dart:convert' show json;
import 'package:flutter_common_app/data/protection.dart';

class BannerData {
  BannerData({
    this.pic,
    this.targetId,
    this.adid,
    this.targetType,
    this.titleColor,
    this.typeTitle,
    this.url,
    this.adurlV2,
    this.exclusive,
    this.monitorImpress,
    this.monitorClick,
    this.monitorType,
    this.monitorImpressList,
    this.monitorClickList,
    this.monitorBlackList,
    this.extMonitor,
    this.extMonitorInfo,
    this.adSource,
    this.adLocation,
    this.encodeId,
    this.program,
    this.event,
    this.video,
    this.dynamicVideoData,
    this.song,
    this.bannerId,
    this.alg,
    this.scm,
    this.requestId,
    this.showAdTag,
    this.pid,
    this.showContext,
    this.adDispatchJson,
  });

  factory BannerData.fromJson(Map<String, dynamic> jsonRes) {
    if (jsonRes == null) {
      return null;
    }

    final List<Object> monitorImpressList =
    jsonRes['monitorImpressList'] is List ? <Object>[] : null;
    if (monitorImpressList != null) {
      for (final dynamic item in jsonRes['monitorImpressList']) {
        if (item != null) {
          tryCatch(() {
            monitorImpressList.add(asT<Object>(item));
          });
        }
      }
    }

    final List<Object> monitorClickList =
    jsonRes['monitorClickList'] is List ? <Object>[] : null;
    if (monitorClickList != null) {
      for (final dynamic item in jsonRes['monitorClickList']) {
        if (item != null) {
          tryCatch(() {
            monitorClickList.add(asT<Object>(item));
          });
        }
      }
    }
    return BannerData(
      pic: asT<String>(jsonRes['pic']),
      targetId: asT<int>(jsonRes['targetId']),
      adid: asT<Object>(jsonRes['adid']),
      targetType: asT<int>(jsonRes['targetType']),
      titleColor: asT<String>(jsonRes['titleColor']),
      typeTitle: asT<String>(jsonRes['typeTitle']),
      url: asT<String>(jsonRes['url']),
      adurlV2: asT<Object>(jsonRes['adurlV2']),
      exclusive: asT<bool>(jsonRes['exclusive']),
      monitorImpress: asT<Object>(jsonRes['monitorImpress']),
      monitorClick: asT<Object>(jsonRes['monitorClick']),
      monitorType: asT<Object>(jsonRes['monitorType']),
      monitorImpressList: monitorImpressList,
      monitorClickList: monitorClickList,
      monitorBlackList: asT<Object>(jsonRes['monitorBlackList']),
      extMonitor: asT<Object>(jsonRes['extMonitor']),
      extMonitorInfo: asT<Object>(jsonRes['extMonitorInfo']),
      adSource: asT<Object>(jsonRes['adSource']),
      adLocation: asT<Object>(jsonRes['adLocation']),
      encodeId: asT<String>(jsonRes['encodeId']),
      program: asT<Object>(jsonRes['program']),
      event: asT<Object>(jsonRes['event']),
      video: asT<Object>(jsonRes['video']),
      dynamicVideoData: asT<Object>(jsonRes['dynamicVideoData']),
      song: asT<Object>(jsonRes['song']),
      bannerId: asT<String>(jsonRes['bannerId']),
      alg: asT<Object>(jsonRes['alg']),
      scm: asT<String>(jsonRes['scm']),
      requestId: asT<String>(jsonRes['requestId']),
      showAdTag: asT<bool>(jsonRes['showAdTag']),
      pid: asT<Object>(jsonRes['pid']),
      showContext: asT<Object>(jsonRes['showContext']),
      adDispatchJson: asT<Object>(jsonRes['adDispatchJson']),
    );
  }

  final String pic;
  final int targetId;
  final Object adid;
  final int targetType;
  final String titleColor;
  final String typeTitle;
  final String url;
  final Object adurlV2;
  final bool exclusive;
  final Object monitorImpress;
  final Object monitorClick;
  final Object monitorType;
  final List<Object> monitorImpressList;
  final List<Object> monitorClickList;
  final Object monitorBlackList;
  final Object extMonitor;
  final Object extMonitorInfo;
  final Object adSource;
  final Object adLocation;
  final String encodeId;
  final Object program;
  final Object event;
  final Object video;
  final Object dynamicVideoData;
  final Object song;
  final String bannerId;
  final Object alg;
  final String scm;
  final String requestId;
  final bool showAdTag;
  final Object pid;
  final Object showContext;
  final Object adDispatchJson;

  Map<String, dynamic> toJson() => <String, dynamic>{
    'pic': pic,
    'targetId': targetId,
    'adid': adid,
    'targetType': targetType,
    'titleColor': titleColor,
    'typeTitle': typeTitle,
    'url': url,
    'adurlV2': adurlV2,
    'exclusive': exclusive,
    'monitorImpress': monitorImpress,
    'monitorClick': monitorClick,
    'monitorType': monitorType,
    'monitorImpressList': monitorImpressList,
    'monitorClickList': monitorClickList,
    'monitorBlackList': monitorBlackList,
    'extMonitor': extMonitor,
    'extMonitorInfo': extMonitorInfo,
    'adSource': adSource,
    'adLocation': adLocation,
    'encodeId': encodeId,
    'program': program,
    'event': event,
    'video': video,
    'dynamicVideoData': dynamicVideoData,
    'song': song,
    'bannerId': bannerId,
    'alg': alg,
    'scm': scm,
    'requestId': requestId,
    'showAdTag': showAdTag,
    'pid': pid,
    'showContext': showContext,
    'adDispatchJson': adDispatchJson,
  };
  @override
  String toString() {
    return json.encode(this);
  }

  static List<BannerData> fromJsonList(List json) {
    return json.map((item) => BannerData.fromJson(item)).toList();
  }
}
